<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class MY_Form_validation extends CI_Form_validation {

    function __construct()
    {
        parent::__construct();
    }

    // --------------------------------------------------------------------

    /**
     * Valid Date (ISO format)
     *
     * @access    public
     * @param    string
     * @return    bool
     */
    public function _ValidDate($date) {

        if (count(explode('-',$date)) == 3) 
        {
        $pattern = "/^([0-9]{2})".'-'."([0-9]{2})".'-'."([0-9]{4})$/";
            if (preg_match ($pattern, $date, $parts))  
            {
                if (checkdate($parts[2],$parts[1],$parts[3]))
                    return true;
                /* This is a valid date */
                else
                    return false;
                /* This is an invalid date */
                //echo "fecha inválida";
                $this->form_validation->set_message('_ValidDate','"fecha inválida"');
            }  else  {
            return false;
            /* This is an invalid date in terms of format */
            //echo "formato de fecha inválida";
            $this->form_validation->set_message('_ValidDate','"formato de fecha inválida"');
            }
        } else {
        return false;
        /* Day, Month, Year - either of them not present */
        $this->form_validation->set_message('_ValidDate','"Dia, Mes, Año o ninguno de ellos esta presente"');
        //echo "Dia, Mes, Año o ninguno de ellos esta presente"; 
        }
    }
    
}
